
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>数据源项管理</title>
     <#include "../StaticFile.ftl">
    <script>
    
    

    var toolbar = [{
            text:'新增数据源数据',
            iconCls:'icon-add',
            handler:function(){global.id=0;$('#dlg').dialog('open');clean();}
        }];
    
    </script>
</head>
<body>




<div id="cc" class="easyui-layout" style="width:100%;height:900px;">
     <#include "../Head.ftl">
     <#include "../Menu.ftl">
    <div data-options="region:'center',title:'数据显示区',split:true">
     <div style="margin-top:10px;padding-bottom:10px;">
    应用名称:<input class="easyui-textbox" type="text" id="search_title" name="search_title" ></input>
    应用包名:<input class="easyui-textbox" type="text" id="search_packagename" name="search_packagename" ></input>
     <a href="javascript:void(0)" class="easyui-linkbutton" onclick="doSearch()">查询</a> 
    </div>
   
    <table id="dg" title="数据源项管理" style="width:100%" data-options="
                singleSelect:true,
                autoRowHeight:false,
                pagination:true,
                url:'/datasource/getdata?sourceId='+global.source_id,
                pageSize:20,toolbar:toolbar">
        <thead>
            <tr>
                <th field="id" width="120" align="center">编号</th>
                 <th data-options="field:'name',width:160,align:'center'">数据源名称</th>
                <th data-options="field:'title',width:180,align:'center'" >APP名称</th>
                 <th data-options="field:'order_priority',width:180,align:'center'" >排列顺序</th>
                 <th data-options="field:'icon',width:100,align:'center',formatter:formatIcon" >图标</th>
                <th data-options="field:'packagename',width:150,align:'center'" >APP包名</th>
                 <th data-options="field:'categoryName',width:120,align:'center'" >分类名称</th>
                  <th data-options="field:'companyName',width:180,align:'center'" >厂商名称</th>
                <th data-options="field:'operation',width:150,align:'center',formatter:formatOperation" >操作</th>
            </tr>
        </thead>
    </table>
   
    <div id="dlg" class="easyui-dialog" title="添加数据源项" data-options="iconCls:'icon-save'" style="width:300px;height:180px;padding:10px;">
        
            <table cellpadding="5">
               
                <tr>
                    <td>appId:</td>
                    <td><input class="easyui-textbox" type="text" name="appId" id="appId" data-options="required:true,validType:'email'"></input></td>
                </tr>
                
                <tr>
                    <td>顺序:</td>
                    <td><input class="easyui-textbox" type="text" name="order_priority" id="order_priority" data-options="required:true,validType:'email'"></input></td>
                </tr>
                </tr>
                 
            </table>
       
         <div style="text-align:center;padding:5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="addElement()">添加</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">取消</a> 
         </div>
        </div>
       
      </div></div>
     <script>
     
        var global={"source_id":#{source_id},"id":0}
        function clearForm()
        {
        $('#dlg').dialog('close');
        }
        
          $(function(){
            var pager = $('#dg').datagrid().datagrid('getPager');
            $('#dlg').dialog('close');
             })
               // get the pager of datagrid
               
         function doSearch(){
            $('#dg').datagrid('load',{
         
            "title":$("#search_title").textbox("getValue"),
            "packagename":$("#search_packagename").textbox("getValue")
            });
            }
            function addElement()
            {
                
                 if(!window.confirm("确定要保存么？"))
                {
                    return;
                }
                var appId=$("#appId").textbox("getValue");
                var order_priority=$("#order_priority").textbox("getValue");
                if(!appId){
                    alert("appid不能为空");
                }
                 if(!order_priority){
                    alert("排序不能为空");
                }
                $.ajax({
                type: "POST",
                  url: "/datasource/add",
                  data:{
                  id:global.id,
                  appId:appId,
                   order_priority:order_priority,
                  sourceId:global.source_id
                  },
                  success:function(data)
                  {
                    //var result=jQuery.parseJSON(data);
                    
                    doSearch();
                    $('#dlg').dialog('close');
                    
                  }
                  });
            }
            
            function clean()
            {
                  global.id=0;
                  $("#appId").textbox("setValue","");
                  $("#order_priority").textbox("setValue","")
            }
        function formatOperation(val,row)
        {
        
           
            
                return '<a href="javascript:void(0)" class="easyui-linkbutton" style="padding-right:5px;" onclick="deleteElement('+row.id+')">删除</a><a href="javascript:void(0)" class="easyui-linkbutton" style="padding-right:5px;" onclick="editElement('+row.id+')">编辑</a>';
            
           
        }
        
         function formatCreatDate(val,row)
        {
        
            return formatTime(val);
        }
       
         function deleteElement(id)
            {
            
             if(!window.confirm("确定要删除么？"))
                {
                    return;
                }
                $.ajax({ type: "GET",
                url: "/datasource/delete?id="+id+"&sourceId="+global.source_id,
                success: function(data)
                 {
                    var returnData=jQuery.parseJSON(data);
                    if(returnData.code==0)
                    {
                    // $('#dlg').dialog('close');
                        doSearch(); 
                        
                      // alert("chenggong");
                    }
                  }});
            }
       
       function editElement(id){
       
               $.ajax({ type: "GET",
                url: "/datasource/getElement?id="+id,
                success: function(data)
                 {
                    var returnData=jQuery.parseJSON(data);
                    if(returnData.code==0)
                    {
                     $('#dlg').dialog('open');
                      global.id=id;
                      $("#appId").textbox("setValue",returnData.data.app_id);
                      $("#order_priority").textbox("setValue",returnData.data.order_priority)
                      
                    }
                  }});
       }
         function formatIcon(val,row)
        {
           return "<img style='high:30px;width:30px' src='"+val+"'/>";
        } 
        
      
       
         </script>
    
</body>
</html>